package com.ruoyi.system.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.ruoyi.system.domain.SysAuditLog;
import com.ruoyi.system.mapper.SysAuditLogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysQualificationMaterialMapper;
import com.ruoyi.system.domain.SysQualificationMaterial;
import com.ruoyi.system.service.ISysQualificationMaterialService;

/**
 * 资质材料信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-10-27
 */
@Service
public class SysQualificationMaterialServiceImpl implements ISysQualificationMaterialService 
{
    @Autowired
    private SysQualificationMaterialMapper sysQualificationMaterialMapper;


    @Autowired
    private SysAuditLogMapper sysAuditLogMapper;

    /**
     * 查询资质材料信息
     * 
     * @param qualificationMaterialId 资质材料信息主键
     * @return 资质材料信息
     */
    @Override
    public SysQualificationMaterial selectSysQualificationMaterialByQualificationMaterialId(Long qualificationMaterialId)
    {
        return sysQualificationMaterialMapper.selectSysQualificationMaterialByQualificationMaterialId(qualificationMaterialId);
    }

    /**
     * 查询资质材料信息列表
     * 
     * @param sysQualificationMaterial 资质材料信息
     * @return 资质材料信息
     */
    @Override
    public List<SysQualificationMaterial> selectSysQualificationMaterialList(SysQualificationMaterial sysQualificationMaterial)
    {
        return sysQualificationMaterialMapper.selectSysQualificationMaterialList(sysQualificationMaterial);
    }

    /**
     * 新增资质材料信息
     * 
     * @param sysQualificationMaterial 资质材料信息
     * @return 结果
     */
    @Override
    public int insertSysQualificationMaterial(SysQualificationMaterial sysQualificationMaterial)
    {
        return sysQualificationMaterialMapper.insertSysQualificationMaterial(sysQualificationMaterial);
    }

    /**
     * 修改资质材料信息
     * 
     * @param sysQualificationMaterial 资质材料信息
     * @return 结果
     */
    @Override
    public int updateSysQualificationMaterial(SysQualificationMaterial sysQualificationMaterial)
    {
        return sysQualificationMaterialMapper.updateSysQualificationMaterial(sysQualificationMaterial);
    }

    /**
     * 批量删除资质材料信息
     * 
     * @param qualificationMaterialIds 需要删除的资质材料信息主键
     * @return 结果
     */
    @Override
    public int deleteSysQualificationMaterialByQualificationMaterialIds(Long[] qualificationMaterialIds)
    {
        return sysQualificationMaterialMapper.deleteSysQualificationMaterialByQualificationMaterialIds(qualificationMaterialIds);
    }

    /**
     * 删除资质材料信息信息
     * 
     * @param qualificationMaterialId 资质材料信息主键
     * @return 结果
     */
    @Override
    public int deleteSysQualificationMaterialByQualificationMaterialId(Long qualificationMaterialId)
    {
        return sysQualificationMaterialMapper.deleteSysQualificationMaterialByQualificationMaterialId(qualificationMaterialId);
    }

    /**
     *
     * @param sysQualificationMaterial 资质材料信息
     * @return
     */
    @Override
    public int apply(SysQualificationMaterial sysQualificationMaterial) {

        if("2".equals(sysQualificationMaterial.getQualificationStatus())){

            sysQualificationMaterial.setRemark("");
        }
        sysQualificationMaterialMapper.updateSysQualificationMaterial(sysQualificationMaterial);
        SysAuditLog sysAuditLog = new SysAuditLog();
        sysAuditLog.setUserId(sysQualificationMaterial.getUserId());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        sysAuditLog.setLogTime(new Date());
        sysAuditLog.setDepict(sysQualificationMaterial.getRemark());
        sysAuditLog.setEvent("审核操作");
        //当前登录用户
        sysAuditLog.setOperator("admin");
       return  sysAuditLogMapper.insertSysAuditLog(sysAuditLog);

    }
}
